<template>
	<view class="my-userinfo-container">
		<!-- 头像昵称区域 -->
		<view class="top-box">
			<image :src="userinfo.avatarUrl" class="avatar"></image>
			<view class="nickname">{{userinfo.nickName}}</view>
		</view>
		<view class="panel-list">
			<view class="panel-top panel">
				<view class="panel-item" v-for="(item, index) in panelTop" :key="index">
					<text>{{item.num}}</text>
					<text>{{item.desc}}</text>
				</view>
			</view>
			<view class="panel-center">
				<!-- 面板的标题 -->
				<view class="panel-title">我的订单</view>
				<!-- 面板的主体 -->
				<view class="panel-body panel">
					<!-- 面板主体中的 item 项 -->
					<view class="panel-item" v-for="(item, index) in panelCenter" :key="index">
						<image :src="item.icon" class="icon"></image>
						<text>{{item.desc}}</text>
					</view>
				</view>
			</view>
			<view class="panel-bottom">
				<view class="panel-list-item">
					<text>收货地址</text>
					<uni-icons type="right" size="15"></uni-icons>
				</view>
				<view class="panel-list-item">
					<text>联系客服</text>
					<uni-icons type="right" size="15"></uni-icons>
				</view>
				<view class="panel-list-item" @click="logout">
					<text>退出登录</text>
					<uni-icons type="right" size="15"></uni-icons>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex';
	export default {
		name: 'my-userinfo',
		data() {
			return {
				panelTop: [
					{
						desc: '收藏的店铺',
						num: 9,
					},
					{
						desc: '收藏的商品',
						num: 25,
					},
					{
						desc: '足迹',
						num: 17,
					},
					{
						desc: '卡包',
						num: 5,
					},
				],
				panelCenter: [
					{
						icon: '/static/my-icons/icon1.png',
						desc: '待付款',
					},
					{
						icon: '/static/my-icons/icon2.png',
						desc: '待收货',
					},
					{
						icon: '/static/my-icons/icon3.png',
						desc: '退款/退货',
					},
					{
						icon: '/static/my-icons/icon4.png',
						desc: '全部订单',
					},
				],
				panelBottom: ['收货'],
			};
		},
		computed: {
			...mapState('m_user', ['userinfo']),
		},
		methods: {
			...mapMutations('m_user', ['updateAddress', 'updateUserInfo', 'updateToken']),
			// 退出登录
			async logout() {
				const [err, success] = await uni
					.showModal({
						title: '提示',
						content: '确认退出登录吗？',
					})
					.catch((err) => err);
				console.log(success);
				if (success && success.confirm) {
					// 清空信息
					this.updateAddress({});
					this.updateUserInfo({});
					this.updateToken('');
				}
			},
		},
	};
</script>

<style lang="scss">
	$bd-radius: 5px;
	.my-userinfo-container {
		height: 100%;
		// 为整个组件的结构添加浅灰色的背景
		background-color: #f4f4f4;

		.top-box {
			height: 400rpx;
			background-color: #c00000;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.avatar {
				display: block;
				width: 90px;
				height: 90px;
				border-radius: 45px;
				border: 2px solid white;
				box-shadow: 0 1px 5px black;
			}

			.nickname {
				color: white;
				font-weight: bold;
				font-size: 16px;
				margin-top: 10px;
			}
		}
		.panel-list {
			position: relative;
			top: -10px;
			padding: 0 10px;
			.panel-top {
				background-color: white;
			}
			.panel-center {
				background-color: white;
				border-radius: $bd-radius;
				.panel-title {
					line-height: 45px;
					padding-left: 10px;
					font-size: 15px;
					border-bottom: 1px solid #f4f4f4;
				}
				.panel-body {
					display: flex;
					justify-content: space-around;
					border-radius: 5px;
					padding: 10px 0;
					.icon {
						width: 35px;
						height: 35px;
					}
				}
			}
			.panel-bottom {
				background-color: white;
				border-radius: $bd-radius;
				margin-bottom: 8px;
				.panel-list-item {
					height: 45px;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 15px;
					padding: 0 10px;
				}
			}
			// 公共样式
			.panel {
				display: flex;
				background-color: white;
				justify-content: space-around;
				margin-bottom: 8px;
				border-radius: $bd-radius;
				padding: 10px 0;
				.panel-item {
					font-size: 13px;
					display: flex;
					flex-direction: column;
					align-items: center;
				}
			}
		}
	}
</style>
